package com.onlineMIS.action.headQ.report;

import java.io.InputStream;
import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.onlineMIS.ORM.DAO.Response;
import com.onlineMIS.ORM.entity.headQ.custMgmt.HeadQCust;
import com.onlineMIS.ORM.entity.headQ.report.HeadQPurchaseStatisticReportItemVO;
import com.onlineMIS.ORM.entity.headQ.user.UserInfor;
import com.onlineMIS.common.Common_util;
import com.onlineMIS.common.loggerLocal;
import com.onlineMIS.filter.SystemParm;
import com.opensymphony.xwork2.ActionContext;

public class HeadQReportJSPAction extends HeadQReportAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4965927215338212593L;
	private String excelFileName = "";
	private InputStream excelStream;
	private final String HQ_SALES_STATISC_REPORT_TEMPLATENAME = "HqSalesStatisticsReportTemplate.xls";
	private final  String TEMPLATE_FILE_NAME = "HeadQPurchaseStatisticsReportTemplate.xls";
	private final  String TEMPLATE_FILE_LEVEL_NAME = "HeadQPurchaseStatisticsLevelReportTemplate.xls";
	private final  String TEMPLATE_FILE_NAME_DETAILS = "HeadQPurchaseStatisticsDetailsReportTemplate.xls";
	private final String HQ_SALES_STATISC_LEVEL_REPORT_TEMPLATENAME = "HqSalesStatisticsLevelReportTemplate.xls";
	private final String HQ_SALES_STATISC_DETAIL_REPORT_TEMPLATENAME2007 = "HqSalesStatisticsDetailReportTemplate2007.xlsx";
	private final String templateHeadCust = "HeadUnitReportTemplate.xls";
	private final String DEALINGS_TEMPLATE = "HeadDealingsReportTemplate.xls";
	private final String HQ_TABLET_DISTRIBUTION_TEMPLATE ="HqTabletDistributionTemplate.xls";
	
	public InputStream getExcelStream() {
		return excelStream;
	}

	public void setExcelStream(InputStream excelStream) {
		this.excelStream = excelStream;
	}

	public String getExcelFileName() {
		   return this.excelFileName;
	}

	public void setExcelFileName(String excelFileName) {
		this.excelFileName = Common_util.encodeAttachment(excelFileName);
	}
	/**
	 * 总部采购报表
	 * @return
	 */
	public String preGeneratePurchaseReport(){
		loggerLocal.info(this.getClass().getName()+ ".preGeneratePurchaseReport");
    	
		headQReportService.preparePurchaseReportUI(formBean,uiBean);
		
		return "purchaseReport";
	}
	
	/**
	 * 总部销售报表
	 * @return
	 */
	public String preGenerateHqSalesReport(){
		loggerLocal.info(this.getClass().getName()+ ".preGenerateSalesReport");
		headQReportService.prepareSalesReportUI(formBean,uiBean);
		return "hqSalesReport";		
	}
	
	/**
	 * 总部销售报表详情页面
	 * @return
	 */
	public String preGenerateHqSalesReportDetails(){
		loggerLocal.info(this.getClass().getName()+ ".preGenerateHqSalesReportDetails");
		//headQReportService.prepareSalesReportUI(formBean,uiBean);
		return "salesReport";		
	}
	
	
	
	
	/**
	 * 总部平板配货统计
	 * @return
	 */
	public String preTabletDistribution(){
		loggerLocal.info(this.getClass().getName()+ ".preGenerateSalesReport");
		headQReportService.prepareSalesReportUI(formBean,uiBean);
		return "hqTabletDistribution";		
	}
	
	/**
	 * 总部平板配货统计详情页面
	 * @return
	 */
	public String preTabletDistributionDetails(){
		loggerLocal.info(this.getClass().getName()+ ".preTabletDistributionDetails");
		return "hqTabletDistributionDetails";		
	}
	
	
	/**
	 * 追踪客户采购信息
	 * @return
	 */
	public String selectSalesRecords(){
		loggerLocal.info(this.getClass().getName()+ ".selectSalesRecords");
		Response response = headQReportService.selectSalesRecords(formBean);
		if (response.getReturnCode() == Response.SUCCESS) {
			Map<String, List> data = (Map<String, List>) response.getReturnValue();
			List<SalesRecordsVO> traceVOs = data.get("rows");

			uiBean.setTraceItems(traceVOs);
		}
		return "salesReportDetails";	
	}
	
	/**
	 * 追踪客户选货的配货跟踪信息
	 * @return
	 */
	public String getPeiHuoTraceRecords(){
		loggerLocal.info(this.getClass().getName()+ ".getPeiHuoTraceRecords");
		Response response = headQReportService.getPeiHuoTraceRecords(formBean.getCust().getId(), formBean.getBarcode(),formBean.getSearchStartTime(), formBean.getSearchEndTime(),formBean.getReportType());
		if (response.getReturnCode() == Response.SUCCESS) {
			List<SalesRecordsVO> traceVOs = (List<SalesRecordsVO>) response.getReturnValue();
			uiBean.setTraceItems(traceVOs);
		}
		return "peiHuoTraceRecords";	
	}
	
	/**
	 * 生成销售统计报表的excel格式
	 * @return
	 */
	public String generateHqSalesStatisticExcelReport(){
		loggerLocal.info(this.getClass().getName()+ "."+"generateHqSalesStatisticExcelReport");

		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
			response = headQReportService.generateChainSalesStatisticExcelReport(formBean.getParentId(),formBean.getCust().getId(), formBean.getBarcode(), formBean.getStartDate(), formBean.getEndDate(), formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(), formBean.getBrand().getBrand_ID(),formBean.getCategoryLevel().getCategory_ID(),formBean.getCategory().getCategory_ID(), contextPath + "WEB-INF\\template\\" + HQ_SALES_STATISC_REPORT_TEMPLATENAME);     
		} catch (Exception e) {
			e.printStackTrace();
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("SalesStatisticExcelReport.xls");
		    return "reportTwo"; 
		} else 
			return ERROR;		
	}
	
	
	/**
	 * 下载平板配货报表
	 * @return
	 */
	public String downloadTabletExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadSalesExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
			
		     response = headQReportService.downloadTabletExcelReport(formBean.getParentId(), formBean.getSearchStartTime(),
						formBean.getSearchEndTime(), formBean.getCust().getId(), formBean.getBarcode(),formBean.getBelongTo(),
						formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(),
						formBean.getBrand().getBrand_ID(), formBean.getCategoryLevel().getCategory_ID(),
						formBean.getCategory().getCategory_ID(), formBean.getReportType(),contextPath + "WEB-INF\\template\\" + HQ_TABLET_DISTRIBUTION_TEMPLATE);
		} catch (Exception e) {
			e.printStackTrace();
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("peihuo.xls");
		    return "reportTwo"; 
		} else 
			return ERROR;	
	}
	
	/**
	 * 生成销售统计层级报表
	 * @return
	 */
	public String generateHqSalesStatisticLevelReport(){
		loggerLocal.info(this.getClass().getName()+ "."+"generateHqSalesStatisticLevelReport");

		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		
			@SuppressWarnings("unchecked")
			List<HqSalesStatisticReportItemVO> list =  (List<HqSalesStatisticReportItemVO>) headQReportService.getSalesStatisticReptEles(formBean.getParentId(), formBean.getStartDate(),
			formBean.getEndDate(), formBean.getCust().getId(), formBean.getBarcode(),formBean.getBelongTo(),
			formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(),
			formBean.getBrand().getBrand_ID(), formBean.getCategoryLevel().getCategory_ID(),
			formBean.getCategory().getCategory_ID(), formBean.getReportType()).getReturnValue();     

			response = headQReportService.generateHqSalesStatisticLevelReport(list,formBean.getCust().getId(),contextPath + "WEB-INF\\template\\" + HQ_SALES_STATISC_LEVEL_REPORT_TEMPLATENAME,formBean.getStartDate(),formBean.getEndDate());     
		} catch (Exception e) {
			loggerLocal.error(e);
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("SalesStatisticLevelReport.xlsx");
		    return "reportTwo"; 
		} else 
			return ERROR;		
	}
	
	
	/**
	 * 生成销售统计报表明晰的excel格式
	 * @return
	 */
	public String generateHqSalesStatisticExcelDetailReport(){
		loggerLocal.info(this.getClass().getName()+ "."+"generateHqSalesStatisticExcelDetailReport");

		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
			response = headQReportService.generateChainSalesStatisticExcelReportDetail(formBean.getParentId(),formBean.getCust().getId(),formBean.getBarcode(), formBean.getStartDate(), formBean.getEndDate(), formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(), formBean.getBrand().getBrand_ID(), formBean.getCategoryLevel().getCategory_ID(),formBean.getCategory().getCategory_ID(), contextPath + "WEB-INF\\template\\" + HQ_SALES_STATISC_DETAIL_REPORT_TEMPLATENAME2007);     
		} catch (Exception e) {
			loggerLocal.error(e);
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("SalesStatisticExcelReport.xlsx");
		    return "reportTwo"; 
		} else 
			return ERROR;		
	}
	
	
	/**
	 * 总部单位销售统计
	 * @return
	 */
	public String unitSalesReport() {
		loggerLocal.info(this.getClass().getName()+ ".unitSalesReport");
		headQReportService.prepareUnitReportUI(formBean,uiBean);
		return "unitSalesReport";
	}
	
	/**
	 * 总部单位销售统计 - 详情
	 * @return
	 */
	public String unitSalesReportDetails() {
		loggerLocal.info(this.getClass().getName()+ ".unitSalesReport");
		headQReportService.getUnitSalesReportDetails(formBean);
		return "unitSalesReportDetails";
	}
	

	
	
	/**
	 * 下载 总部单位销售统计单据
	 * @return
	 */																					
	public String downloadReportInfo() {
		UserInfor userInfor = (UserInfor)ActionContext.getContext().getSession().get(Common_util.LOGIN_USER);
		loggerLocal.info(this.getClass().getName() + ".downloadAcctFlow");
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext()
				.get(ServletActionContext.HTTP_REQUEST);
		String contextPath = request.getRealPath("/");
		Response response = new Response();
		try { 
			response = headQReportService.generateHeadUnitExcel(
					contextPath + "WEB-INF\\template\\" + templateHeadCust, formBean,userInfor);
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}

		if (response.getReturnCode() == Response.SUCCESS) {
			InputStream excelStream = (InputStream) response.getReturnValue();
			formBean.setFileStream(excelStream); 
			formBean.setFileName(templateHeadCust);
			return "report";
		} else
			return ERROR;
	}
	
	
	/**
	 * 进入往来分析报表查询页面
	 * @return
	 * @throws ParseException 
	 */
	public String dealingsAnalysisReport() throws ParseException {
		loggerLocal.info(this.getClass().getName()+ ".unitSalesReport");
		headQReportService.prepareUnitReportUI(formBean,uiBean);
		return "dealingsAnalysis";
	}
	
	
	
	/**
	 * 总部客户往来帐目报表
	 * @return
	 */
	public String preGenerateCustAcctFlowReport(){
		loggerLocal.info(this.getClass().getName()+ ".preGenerateCustAcctFlowReport");
		
		headQReportService.prepareAcctFlowReportUI(formBean, uiBean);
    	
		return "CustAcctFlowReport";		
	}
	
	/**
	 * 总部供应商往来帐目报表
	 * @return
	 */
	public String preGenerateSupplierAcctFlowReport(){
		loggerLocal.info(this.getClass().getName()+ ".preGenerateSupplierAcctFlowReport");
		
		headQReportService.prepareAcctFlowReportUI(formBean, uiBean);
    	
		return "CustSupplierFlowReport";		
	}
	
	/**
	 * 总部销售报表
	 * @return
	 */
	public String preGenerateHQExpenseReport(){
		loggerLocal.info(this.getClass().getName()+ ".preGenerateHQExpenseReport");
		
		headQReportService.prepareHQExpenseReportUI(formBean);
    	
		return "HQExpenseReport";		
	}
	
	/**
	 * 下载 采购统计报表
	 * @return
	 */
	public String downloadPurchaseExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadPurchaseExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadPurchaseExcelReport(formBean.getParentId(), formBean.getOrder().getSupplier().getId(), formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(), formBean.getBrand().getBrand_ID(), formBean.getStartDate(), formBean.getEndDate(),contextPath + "WEB-INF\\template\\headQ\\" + TEMPLATE_FILE_NAME);
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    formBean.setFileStream(excelStream);
			formBean.setFileName("CaiGouTongJiBaoBiao.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	
	/**
	 * 下载 采购统计层级报表
	 * @return
	 */
	public String downloadPurchaseLevelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadPurchaseExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
			int supplierId = 0;
			if (formBean.getOrder().getSupplier() == null)
				supplierId = 0;
			else 
				supplierId = formBean.getOrder().getSupplier().getId();
			List<HeadQPurchaseStatisticReportItemVO> itemVOs = (List<HeadQPurchaseStatisticReportItemVO>) headQReportService.getPurchaseStatisticReptEles(formBean.getParentId(), formBean.getStartDate(), formBean.getEndDate(), supplierId, formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(), formBean.getBrand().getBrand_ID(), formBean.getReportType(), formBean.getBelongTo()).getReturnValue();

		     response = headQReportService.downloadPurchaseLevelReport(itemVOs,formBean.getStartDate(), formBean.getEndDate(),contextPath + "WEB-INF\\template\\headQ\\" + TEMPLATE_FILE_LEVEL_NAME);
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    formBean.setFileStream(excelStream);
			formBean.setFileName("CaiGouLevel.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	
	/**
	 * 下载 采购统计报表
	 * @return
	 */
	public String downloadPurchaseExcelReportDetails(){
		loggerLocal.info(this.getClass().getName()+ ".downloadPurchaseExcelReportDetails");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadPurchaseDetailsExcelReport(formBean.getParentId(), formBean.getOrder().getSupplier().getId(), formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(), formBean.getBrand().getBrand_ID(), formBean.getStartDate(), formBean.getEndDate(),contextPath + "WEB-INF\\template\\headQ\\" + TEMPLATE_FILE_NAME_DETAILS);
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    formBean.setFileStream(excelStream);
			formBean.setFileName("CaiGouTongJiBaoBiao.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	
	/**
	 * 下载 销售统计报表
	 * @return
	 */
	public String downloadSalesExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadSalesExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
			
		     response = headQReportService.downloadSalesExcelReport(formBean.getParentId(), formBean.getOrder().getClient_id(), formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID(), formBean.getBrand().getBrand_ID(), formBean.getStartDate(), formBean.getEndDate(),contextPath + "WEB-INF\\template\\headQ");
		} catch (Exception e) {
			e.printStackTrace();
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("XiaoShouTongJiBaoBiao.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	

	
	/**
	 * 下载 客户信息 成excel
	 * @return
	 */
	public String downloadCustExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadCustExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadCustInforExcelReport(contextPath + "WEB-INF\\template\\headQ");
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("KeHuXinXi.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	
	/**
	 * 下载 供应砂锅内信息 成excel
	 * @return
	 */
	public String downloadSupplierExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadSupplierExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadSupplierInforExcelReport(contextPath + "WEB-INF\\template\\headQ");
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("GongYinShangXinXi.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	

	/**
	 * 下载 客户acct flow 成excel
	 * @return
	 */
	public String downloadCustAcctFlowExcel(){
		loggerLocal.info(this.getClass().getName()+ ".downloadCustAcctFlowExcel");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadCustAcctFlow(contextPath + "WEB-INF\\template\\headQ", formBean.getSearchStartTime(), formBean.getSearchEndTime(), formBean.getOrder().getCust().getId(),formBean.getTagGroups());
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("KeHuWangLaiZhang.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}

	/**
	 * 下载 客户acct flow 成excel report
	 * @return
	 */
	public String downloadCustAcctFlowExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadCustAcctFlowExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadCustAcctFlowReport(contextPath + "WEB-INF\\template\\headQ", formBean.getStartDate(), formBean.getEndDate(), formBean.getYear().getYear_ID(), formBean.getQuarter().getQuarter_ID());
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("KeHuWangLaiZhang.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	
	/**
	 * 下载 供应商acct flow 成excel report
	 * @return
	 */
	public String downloadSupplierAcctFlowExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadSupplierAcctFlowExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadSupplierAcctFlowReport(contextPath + "WEB-INF\\template\\headQ", formBean.getStartDate(), formBean.getEndDate());
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("GongYinShangWangLaiZhang.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	
	/**
	 * 下载 客户acct flow 成excel report
	 * @return
	 */
	public String downloadExpenseExcelReport(){
		loggerLocal.info(this.getClass().getName()+ ".downloadExpenseExcelReport");
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);   
		String contextPath= request.getRealPath("/"); 

		Response response = new Response();
		try {
		     response = headQReportService.downloadHeadQExpenseReport(contextPath + "WEB-INF\\template\\headQ", formBean.getStartDate(), formBean.getEndDate());
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}
		 
		if (response.getReturnCode() == Response.SUCCESS){
		    InputStream excelStream= (InputStream)response.getReturnValue();
		    this.setExcelStream(excelStream);
		    this.setExcelFileName("ZongBuFeiYongBaoBiao.xls");
		    return "report"; 
		} else 
			return ERROR;	
	}
	
	
	/**
	 * 下载往来分析财务报表
	 * @return
	 */																					
	public String downloadDealingsReportInfo() {
		UserInfor userInfor = (UserInfor)ActionContext.getContext().getSession().get(Common_util.LOGIN_USER);
		loggerLocal.info(this.getClass().getName() + ".downloadDealingsReportInfo");
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext()
				.get(ServletActionContext.HTTP_REQUEST);
		String contextPath = request.getRealPath("/");
		Response response = new Response();
		try { 
			response = headQReportService.generateDealingsExcel(
					contextPath + "WEB-INF\\template\\" + DEALINGS_TEMPLATE, formBean,userInfor);
		} catch (Exception e) {
			response.setReturnCode(Response.FAIL);
			response.setMessage(e.getMessage());
		}

		if (response.getReturnCode() == Response.SUCCESS) {
			InputStream excelStream = (InputStream) response.getReturnValue();
			formBean.setFileStream(excelStream); 
			formBean.setFileName(DEALINGS_TEMPLATE);
			return "report";
		} else
			return ERROR;
	}
	
	/**
	 * 总部采购统计报表
	 * @return
	 */
	public String preGenerateHqPurchaseReportDetails() {
		UserInfor userInfor = (UserInfor)ActionContext.getContext().getSession().get(Common_util.LOGIN_USER);
		loggerLocal.info(this.getClass().getName() + ".preGenerateHqPurchaseReportDetails");
		
		System.out.println(formBean.getStartDate().toString());		
		return "purchaseReportDetail";
	}
}
